import React from 'react';
import { ModalForm, ModalFormProps } from '@ant-design/pro-components';
import { FORM_CONFIG } from '@/options';

type MyFormProps = {
  onFinish: (value: any) => Promise<void> | void;
} & Omit<ModalFormProps, 'onFinish'>;

const MyForm: React.FC<MyFormProps> = ({ children, onFinish, formRef, open, ...props }) => {
  const onOk = async (value: any) => {
    await onFinish(value);
  };

  return (
    <>
      {open && (
        <ModalForm {...FORM_CONFIG} {...props} formRef={formRef} onFinish={onOk} open={open}>
          {children}
        </ModalForm>
      )}
    </>
  );
};

export default MyForm;
